<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class UserController extends Controller {

    /**
     * 获取当前登陆用户的信息
     * @param Request $request
     * @return mixed
     */
    public function curr(Request $request) {
//        $userInfo = $request->session()->get(md5('user'));
        $userInfo =Cache::get(md5('user'));
        unset($userInfo->password);
        unset($userInfo->halt);
        return response()->json(['status' => true, 'data' => $userInfo]);
    }

    public function gets(Request $request) {
        $data   = $request->input();
        $data   = [
            'size' => isset($data['size']) ? intval($data['size']) : '',
            'page' => isset($data['page']) ? intval($data['page']) : '',
        ];
        $offset = (intval($data['page']) - 1) * intval($data['size']);
        //        $sql = sprintf('select * from `user` order by id desc limit %d,%d', 0, 6);
        $ret = $users = DB::table('user')->skip($offset)->take($data['size'])->get()->toArray();
        return $this->ajax(true, $ret);
    }

  
    public function count() {
        $count = DB::table('user')->count();
        return $this->ajax(true, $count);
    }
}
